package com.effectiv.gooruda.business.impl;

import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.effectiv.gooruda.business.api.AbstractBusinessService;
import com.effectiv.gooruda.business.api.SocialProviderService;

import com.effectiv.gooruda.domain.SocialProvider;

import com.effectiv.gooruda.repository.SocialProviderRepository;

@Service
public class SocialProviderServiceImpl extends
		AbstractBusinessService<SocialProvider, String> implements
		SocialProviderService {

	@Autowired
	private SocialProviderRepository repository;

	@Override
	public void save(SocialProvider t) {
		t.setTenant(getTenant());
		t.setProviderKey(UUID.randomUUID().toString());
		super.save(t);
	}

	@Override
	protected void initInternal() {
		setRepository(repository);
	}

	@Override
	public List<SocialProvider> findByType(String type) {
		return repository.findByTenantAndType(getTenant(), type);
	}

	@Override
	public SocialProvider findByProviderKey(String key) {
		return repository.findByProviderKey(key);
	}

}
